package cn.sofwin.jordan;

import cn.sofwin.jordan.entity.User;
import cn.sofwin.jordan.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

@Slf4j
public class Main {

    public static void main(String[] args) {
        String resource = "mybatis-config.xml";
        SqlSessionFactory sqlSessionFactory = null;
        SqlSession session = null;
        try (InputStream inputStream = Resources.getResourceAsStream(resource)) {

            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            session = sqlSessionFactory.openSession();

            UserMapper userMapper = session.getMapper(UserMapper.class);

            User user = userMapper.selectOne(1);
            System.out.println(user);
            log.warn("用户信息：{}", user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

